package enemies;

import java.awt.Dimension;
import java.awt.geom.Point2D;
import java.util.ArrayList;

import javax.swing.ImageIcon;

/**
 * @author onbekend
 * @version 1.1
 * @since 2011-04-11
 */
public abstract class MobileEnemy extends Enemy {

	protected ImageIcon deviceImage;
	protected int deviceAngle = 0;

	/**
	 * 
	 * @param route de route
	 * @param position de positie
	 * @param health de hitpoints
	 * @param size de groote
	 * @param image het plaatje
	 * @param firerate de snelheid waarop de unit schiet
	 * @param range de afstand waarover de unit kan schieten
	 * @param speed de snelheid
	 * @param deviceImage 
	 * @param deviceAngle
	 */
	/* /// Constructor //////////////////////////////////////// */
	MobileEnemy(ArrayList<Point2D.Double> route, Point2D.Double position, int health, Dimension size, ImageIcon image,
			int firerate, int range, int speed, ImageIcon deviceImage, int deviceAngle) {
		super(route, position, health, size, image, firerate, range, speed);
		this.deviceAngle = deviceAngle;
		this.deviceImage = deviceImage;
	}

	/* /// getDeviceAngle //////////////////////////////////////// */
	public int getDeviceAngle() {
		return deviceAngle;
	}

	/* /// setDeviceAngle //////////////////////////////////////// */
	public void setDeviceAngle(int d) {
		deviceAngle = d;
	}

	/**
	 * Past de vijand aan
	 * @see Enemy#update()
	 * @return altijd true
	 */
	/* /// update //////////////////////////////////////// */
	public boolean update() {
		super.update();
		if (aimAtTower != null) {
			double x = aimAtTower.getPosition().x - position.x;
			double y = aimAtTower.getPosition().y - position.y;
			// tower links van enemy
			if (x < 0) {
				// tower hoger dan enemy
				x *= -1;
				if (y < 0) {
					y *= -1;
					deviceAngle = (int) Math.toDegrees((Math.atan((y / x)))) + 90;
				}
				// tower lager dan enemy
				else if (y >= 0) {
					deviceAngle = (int) Math.toDegrees((Math.atan((x / y))));
				}
				// tower rechts van enemy
			} else if (x >= 0) {
				if (y < 0) {
					y *= -1;
					deviceAngle = (int) Math.toDegrees((Math.atan((x / y)))) + 180;
				} else if (y >= 0) {
					deviceAngle = (int) Math.toDegrees((Math.atan((y / x)))) + 270;
				}
			}
		} else {
			deviceAngle = this.viewAngle;
		}
		return true;
	}
}
